package vn.co.thn.web.hotvideo.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import vn.co.thn.web.hotvideo.common.ControllerBase;

@SuppressWarnings("serial")
public class AdminLogin extends ControllerBase {

	@Override
	protected void Get(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		HttpSession session = request.getSession(false);
		if (session != null) {
			String name = (String) session.getAttribute("username");
			if (name != null) {
				request.setAttribute("username", name);
				Forward("admin");
			} else {
				Forward("login");
			}
		} else {
			Forward("login");
		}
	}

	@Override
	protected void Post(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String name = request.getParameter("username");
		String password = request.getParameter("password");
		HttpSession session = request.getSession();
		if (name.equals("hieunghia") && password.equals("abc251184")) {

			session.setAttribute("username", name);
		} else {
			session.invalidate();
		}
		String uri = request.getParameter("url");
		if (uri != null) {
			Redirect(uri);
		} else {
			Redirect("/admin");
		}
	}

}
